<template>
  <div class="app-container">
    <!-- 添加或修改学生列表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-input v-model="form.sex" placeholder="请输入性别" />
        </el-form-item>
        <el-form-item label="身份证" prop="identityCard">
          <el-input v-model="form.identityCard" placeholder="请输入身份证" />
        </el-form-item>
        <el-form-item label="班级" prop="classInfo">
          <el-input v-model="form.classInfo" placeholder="请输入班级" />
        </el-form-item>
        <el-form-item label="电话号码" prop="phoneNumber">
          <el-input v-model="form.phoneNumber" placeholder="请输入电话号码" />
        </el-form-item>
        <el-form-item label="就业老师" prop="jobTeacher">
          <el-input v-model="form.jobTeacher" placeholder="请输入就业老师" />
        </el-form-item>
        <el-form-item label="毕业学校" prop="graduationSchool">
          <el-input
            v-model="form.graduationSchool"
            placeholder="请输入毕业学校"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { addStudentinfo } from "@/api/student/studentinfo";
export default {
  name: "entryStudent",
  data() {
    return {
    // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [{ required: true, message: "姓名不能为空", trigger: "blur" }],
        sex: [{ required: true, message: "性别不能为空", trigger: "change" }],
        identityCard: [
          { required: true, message: "身份证不能为空", trigger: "blur" },
        ],
        classInfo: [
          { required: true, message: "班级不能为空", trigger: "blur" },
        ],
        phoneNumber: [
          { required: true, message: "电话号码不能为空", trigger: "blur" },
        ],
        jobTeacher: [
          { required: true, message: "就业老师不能为空", trigger: "blur" },
        ],
        graduationSchool: [
          { required: true, message: "毕业学校不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
      this.reset();
      this.open = true;
      this.title = "添加学生";
  },
  methods: {
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加学生";
    },
     // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        studentId: null,
        name: null,
        sex: null,
        identityCard: null,
        classInfo: null,
        phoneNumber: null,
        jobTeacher: null,
        graduationSchool: null
      };
      this.resetForm("form");
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.studentId != null) {
            updateStudentinfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStudentinfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    
  },
  
};
</script>

<style>
</style>